[%# The contents of this file are subject to the Mozilla Public
  # License Version 1.1 (the "License"); you may not use this file
  # except in compliance with the License. You may obtain a copy of
  # the License at http://www.mozilla.org/MPL/
  #
  # Software distributed under the License is distributed on an "AS
  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  # implied. See the License for the specific language governing
  # rights and limitations under the License.
  #
  # The Original Code is the Bugzilla Bug Tracking System.
  #
  # The Initial Developer of the Original Code is Netscape Communications
  # Corporation. Portions created by Netscape are
  # Copyright (C) 1998 Netscape Communications Corporation. All
  # Rights Reserved.
  #
  # Contributor(s): Myk Melez <myk@mozilla.org>
  #%]

[% PROCESS global/variables.none.tmpl %]

[% USE Bugzilla %]
[% cgi = Bugzilla.cgi %]

[% PROCESS "global/js-products.html.tmpl" %]

[% PROCESS global/header.html.tmpl
  title="Request Queue"
  style = "
    table.requests th { text-align: left; }
    table#filtering th { text-align: right; }
  "
  onload="var f = document.forms[0]; selectProduct(f.product, f.component, null, null, 'Any');"
  javascript_urls=["js/productform.js"]
%]

<p>
When you are logged in, only requests made by you or addressed to you
are shown by default.  You can change the criteria using the form below.
When you are logged out, all pending requests that are not restricted
to some group are shown by default.
</p>

<form action="request.cgi" method="get">
  <input type="hidden" name="action" value="queue">

  <table id="filtering">
    <tr>
      <th>Requester:</th>
      <td><input type="text" name="requester" value="[% cgi.param('requester') FILTER html %]" size="20" 
           title="Requester's email address"></td>
      <th>Product:</th>
      <td>
        <select name="product" onchange="selectProduct(this, this.form.component, null, null, 'Any');">
          <option value="">Any</option>
          [% FOREACH prod = products %]
            <option value="[% prod.name FILTER html %]"
                    [% "selected" IF cgi.param('product') == prod.name %]>
              [% prod.name FILTER html %]</option>
          [% END %]
        </select>
      </td>
      <th>Flag:</th>
      <td>
        [% PROCESS "global/select-menu.html.tmpl"
                    name="type"
                    options=types
                    default=cgi.param('type') %]
      </td>

      [%# We could let people see a "queue" of non-pending requests. %]
      <!--
      <th>Status:</th>
      <td>
        [%# PROCESS "global/select-menu.html.tmpl"
                    name="status"
                    options=["all", "?", "+-", "+", "-"]
                    default=cgi.param('status') %]
      </td>
      -->

    </tr>
    <tr>
      <th>Requestee:</th>
      <td><input type="text" name="requestee" value="[% cgi.param('requestee') FILTER html %]" size="20" 
           title="Requestee's email address or &quot;-&quot; (hyphen) for requests with no requestee"></td>
      <th>Component:</th>
      <td>
        <select name="component">
          <option value="">Any</option>
          [% FOREACH comp = components %]
            <option value="[% comp FILTER html %]" [% "selected" IF cgi.param('component') == comp %]>
              [% comp FILTER html %]</option>
          [% END %]
        </select>
      </td>
      <th>Group By:</th>
      <td>
        [% groups = {
            "Requester" => 'requester' ,
            "Requestee" => 'requestee',
            "Flag" => 'type' ,
            "Product/Component" => 'category'
          } %]
        [% PROCESS "global/select-menu.html.tmpl" name="group" options=groups default=cgi.param('group') %]
      </td>
      <td><input type="submit" id="filter" value="Filter"></td>
    </tr>
  </table>

</form>

[% column_headers = {
      "type"       => "Flag" ,
      "status"     => "Status" ,
      "bug"        => "$terms.Bug" ,
      "attachment" => "Attachment" ,
      "requester"  => "Requester" ,
      "requestee"  => "Requestee" ,
      "created"    => "Created" ,
      "category"   => "Product/Component"    } %]

[% DEFAULT display_columns = ["requester", "requestee", "type", "bug", "attachment", "created"]
           group_field     = "Requestee"
           group_value     = ""
%]

[% IF debug %]
  <p>[% query FILTER html %]</p>
[% END %]

[% IF requests.size == 0 %]
  <p>
    No requests.
  </p>
[% ELSE %]
  [% FOREACH request = requests %]
    [% IF loop.first %] [% PROCESS start_new_table %] [% END %]
    [% IF request.$group_field != group_value %]
      [% group_value = request.$group_field %]
      [% UNLESS loop.first %]
        </table>
        [% PROCESS start_new_table %]
      [% END %]
    [% END %]
    <tr>
      [% FOREACH column = display_columns %]
        [% NEXT IF column == group_field || excluded_columns.contains(column) %]
        <td>[% PROCESS "display_$column" %]</td>
      [% END %]
    </tr>
  [% END %]
  </table>
[% END %]

[% PROCESS global/footer.html.tmpl %]

[% BLOCK start_new_table %]
  <h3>[% column_headers.$group_field %]: [% (request.$group_field || "None") FILTER html %]</h3>
  <table class="requests" cellspacing="0" cellpadding="4" border="1">
    <tr>
      [% FOREACH column = display_columns %]
        [% NEXT IF column == group_field || excluded_columns.contains(column) %]
        <th>[% column_headers.$column %]</th>
      [% END %]
    </tr>
[% END %]

[% BLOCK display_type %]
  [% request.type FILTER html %]
[% END %]

[% BLOCK display_status %]
  [% request.status %]
[% END %]

[% BLOCK display_bug %]
  <a href="show_bug.cgi?id=[% request.bug_id %]">
    [% request.bug_id %]: [%+ request.bug_summary FILTER html %]</a>
[% END %]

[% BLOCK display_attachment %]
  [% IF request.attach_id %]
[%# if WEBKIT_CHANGES %]
    <a href="attachment.cgi?id=[% request.attach_id %]&amp;action=review">
[%# endif // WEBKIT_CHANGES %]
      [% request.attach_id %]: [%+ request.attach_summary FILTER html %]</a>
  [% ELSE %]
    N/A
  [% END %]
[% END %]

[% BLOCK display_requestee %]
  [% request.requestee FILTER html %]
[% END %]

[% BLOCK display_requester %]
  [% request.requester FILTER html %]
[% END %]

[% BLOCK display_created %]
  [% request.created FILTER time %]
[% END %]

